﻿using CrystalDecisions.CrystalReports.Engine;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.PrintAll
{
    public partial class PrintAJ_JCXH : System.Web.UI.Page
    {
        private ReportDocument m_document;
        protected void Page_Load(object sender, EventArgs e)
        {
            BindReportData("1999-01-01","2018-01-01");
        }

        /// <summary>
        /// 绑定数据到报表
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">截至日期</param>
        private void BindReportData(string startDate,string endDate)
        {

            string strPath = Server.MapPath("~/rpt/CrystalReport_AJ_JCXH.rpt");
            m_document = GetSearchData(startDate,endDate, strPath);
            CrystalReportViewer1.ReportSource = m_document;
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.RefreshReport();
        }

        private ReportDocument GetSearchData(string startDate, string endDate, string strPath)
        {
            IYAKASAPortal.rpt.DsAJ_JCXH ds = new rpt.DsAJ_JCXH();

            IYAKASAPortal.Statistics.TJ_AJ_JCXH obj = new Statistics.TJ_AJ_JCXH();
            DataTable dt = obj.GetSatisticsData(startDate,endDate);

            ReportDocument document = new ReportDocument();
            document.Load(strPath);

            //ds.JCXHTable.AddJCXHTableRow

           // DataRow dr = ds.Tables["JCXHTable"].NewRow();
            int i = 0;
            foreach (DataRow tDr in dt.Rows)
            {
                DataRow dr = ds.Tables["JCXHTable"].NewRow();
               // if (i < 5)  //临时！！！！
                //{
                    dr[string.Format("JCXH{0}", i)] = tDr["JCXH"];
                    dr[string.Format("InitialCheckNum{0}", i)] = tDr["InitialCheckNum"];
                    dr[string.Format("InitialCheckNumQualified{0}", i)] = tDr["InitialCheckNumQualified"];
                    dr[string.Format("InitPercent{0}", i)] = tDr["InitPercent"];
                    dr[string.Format("FirstReview{0}", i)] = tDr["FirstReview"];
                    dr[string.Format("FirstPercent{0}", i)] = tDr["FirstPercent"];
                    dr[string.Format("SecondReview{0}", i)] = tDr["SecondReview"];
                    dr[string.Format("SecondPercent{0}", i)] = tDr["SecondPercent"];
                    dr[string.Format("OtherReview{0}", i)] = tDr["OtherReview"];
                    dr[string.Format("OtherPercent{0}", i)] = tDr["OtherPercent"];
              //  }
                    ds.Tables["JCXHTable"].Rows.Add(dr);

                //i++;
            }
           // ds.Tables["JCXHTable"].Rows.Add(dr);
            document.SetDataSource(ds);
            
            return document;


        }
    }
}